package com.zy.chat.util;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;


@Component
public class ChatRedisUtils {

    @Autowired
    private RedisUtils redisUtils;
    public  HashMap<String,String> createChatNumber(String touser,String username,String content,String type) {
        HashMap<String,String> msg=new HashMap<>();
        TimeUtils timeUtils = new TimeUtils();
        String time = timeUtils.getCurrentTime();
        msg.put("touser",touser);
        msg.put("username",username);
        msg.put("content",content);
        msg.put("time", time);
        msg.put("type",type);
        return msg;
    }

    /**
     * 功能描述：将JavaBean对象的信息缓存进Redis
     *
     * @param map 聊天信息JavaBean
     * @return 是否保存成功
     */
    public void hsaveCacheChatMessage(Map map) {
        String key="chat:singlemsg";
        redisUtils.hsetadd(key,map);
    }

    public void hsaveCacheChatGroupMessage(Map map) {
        String key="chat:groupmsg";
        redisUtils.hsetadd(key,map);
    }


}
